<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 300px;
            height: 300px;
            background-color: darkkhaki;
        }
    </style>
</head>

<body>
    <div>

    </div>
    <script>
        const divObj = document.querySelector("div");
        /* 
            resize:浏览器窗口发生变化的时候会触发该事件
        */
        window.addEventListener("resize", function () {
            console.log(window.innerWidth);
            console.log(window.innerHeight);

            /* 
                如果当前的窗口的宽度小于等于600px就隐藏页面的div
             */
            if (window.innerWidth <= 600) {
                divObj.style.display = 'none';
            } else {
                divObj.style.display = 'block';
            }
        })
    </script>
</body>

</html>